package com.zzptc.gyc.myapp2;

import android.graphics.Color;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;

import java.util.ArrayList;


public class FirstFragment extends Fragment {


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View root = inflater.inflate(R.layout.fragment_first, container, false);
        LineChart lineChart=root.findViewById(R.id.line_Chart);
        ArrayList<Entry> list=new ArrayList<>();
        list.add(new Entry(1,2));
        list.add(new Entry(2,3));
        list.add(new Entry(3,8));
        list.add(new Entry(4,0));
        list.add(new Entry(5,1));

        ArrayList<Entry>list1=new ArrayList<>();
        list1.add(new Entry(1,4));
        list1.add(new Entry(2,5));
        list1.add(new Entry(3,3));
        list1.add(new Entry(4,5));
        list1.add(new Entry(5,4));
        //两个参数
        LineDataSet lineDataSet=new LineDataSet(list,"");//刚刚定义的集合放在这个类里面,美化也是在这里
        LineDataSet lineDataSet1=new LineDataSet(list1,"");
        //第一条坐标点的颜色
        lineDataSet.setCircleColor(Color.BLACK);
        //第二条线的颜色
        lineDataSet1.setColor(Color.RED);
        //线条的宽度
        lineDataSet.setLineWidth(2f);
        //将两条数据放入集合，实质放入两条线
        //ArrayList<ILineDataSet>lineDataSets=new ArrayList<>();
        //lineDataSets.add(lineDataSet);
        //lineDataSets.add(lineDataSet1);

        LineData lineData=new LineData(lineDataSet);
        lineData.addDataSet(lineDataSet1);
        lineChart.setData(lineData);
        //获得设置x轴的值
        XAxis xAxis=lineChart.getXAxis();
        //将x轴放在下面
        xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
        //x最大值
        xAxis.setAxisMaximum(5);
        //x最小值
        xAxis.setAxisMinimum(1);
        //将线平均成5份
        xAxis.setLabelCount(5);
        return root;//return就是结束，一定是放在代码而最后面
    }
}
